import Mock from 'mockjs'
import { param2Obj } from '@/utils'

export default [{
  path: 'sys/login',
  type: 'post',
  template: option => {
    const { username, password } = JSON.parse(option.body)
    if (username === 'admin' && password === '888888') {
      return {
        success: true,
        msg: '',
        data: {
          token: 'adminToken'
        }
      }
    } else {
      return {
        success: false,
        msg: 'ERROR Incorrect username or password',
        data: {}
      }
    }
  }
}, {
  path: 'sys/info',
  type: 'get',
  template: option => {
    const { url } = option
    const query = param2Obj(url)
    if (query.token === 'adminToken') {
      return {
        success: true,
        msg: '',
        data: {
          name: Mock.mock('@name'),
          avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
          modules: ['srm', 'crm', 'sys'],
          menus: [
            'srm.dashboard',
            'srm.order',
            'srm.purchase',
            'srm.outsourcing',
            'srm.delivery',
            'crm.dashboard',
            'crm.order',
            'crm.sale'
          ]
        }
      }
    } else {
      return {
        success: false,
        msg: 'ERROR token',
        data: {}
      }
    }
  }
}]
